﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TUserId = System.Int64;
using TOrderID = System.Int64;//DatabaseAgency.EmGuid;
using TConsumptionRecdID = System.Int64;
using TConsumptionTreeID = System.Int32;

namespace DatabaseAgency
{

    /// <summary>
    /// 酒店下单终端跟服务器通信的相关接口都通过这个IDbAgency来描述
    /// </summary>
    public interface IHotelDbAgency
    {
        /// <summary>
        /// 登录, 用户名和密码都经过简单加密
        /// </summary>
        /// @Param aUserName 用户名
		/// @Param aDepartment 部门
		/// @return 返回值错误码
        /// <param name="password"></param>
        /// <param name="callbackUri">本机的回调类的Uri, 用于监听服务器的广播</param>
        /// <param name="sessionId">会话Id</param>
        /// <returns></returns>
        int Login(string aUserName, string aDepartment , string password, string callbackUri, out int aUserId ,  out string sessionId);

        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="aDepartmentList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetDepartmentList(out List<string> aDepartmentList, out string sessionId);

        /// <summary>
        /// 获取级别列表
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aLevelList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetLevelList(int aUserId, out Dictionary<int, string> aLevelList, out string sessionId);

        /// <summary>
        /// 获取报修类型, 用#分隔内容和code
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aAreaCode"></param>
        /// <param name="aObjectList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetRepaireObject(int aUserId, string aAreaCode, out List<string> aObjectList, string sessionId);

        /// <summary>
        /// 获取报修内容, 用#分隔内容和code
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aAreaCode"></param>
        /// <param name="aRepairObjectCode"></param>
        /// <param name="aContentList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetRepaireContent(int aUserId, string aAreaCode, string aRepairObjectCode, out List<string> aContentList, string sessionId);

        /// <summary>
        /// 获得工程单状态转换表
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aStatusTable"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetOrderStatusTable(int aUserId, out TOrderStatus[,] aStatusTable, out Dictionary<TOrderStatus, string> aStatusNameList, string sessionId);

        /// <summary>
        /// 获取工人列表
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aNameList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetEngineerList( int aUserId , out List<string> aNameList, out string sessionId);

        /// <summary>
        /// 接单
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aOrderId"></param>
        /// <param name="aEngineer">维修得人</param>
        /// <param name="aTime"></param>
        /// <param name="aConsumables"></param>
        /// <param name="aComment"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        //int AcceptOrder(int aUserId, TOrderID aOrderId, string aEngineer, DateTime aTime, string aConsumables, string aComment, string sessionId);

        /// <summary>
        /// 获取耗材列表
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aConsumablesList"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int GetConsumablesList(int aUserId, out List<string> aConsumablesList, out string sessionId);

        /// <summary>
        /// 向服务器发送一个新的报修单
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int NewOrder(int aUserId, string aName, string aDepartment, DateTime aTime, string aLocation, string aRepairObjectCode, string aRepairContentCode, int aLevel, string aNotes, out TOrderID aOrderId, string sessionId);

       /// <summary>
       /// 获取某一天的订单ID
       /// </summary>
       /// <param name="userName"></param>
       /// <param name="orders"></param>
       /// <param name="limit"></param>
       /// <param name="sessionId"></param>
       /// <returns></returns>
       int GetOrdersIdByDate( int aUserId, DateTime aDate , out List<TOrderID> aOrderIdList, string sessionId);
 
        /// <summary>
        /// 根据订单ID获取订单内容
        int GetOrdersById( int aUserId, List<TOrderID> aOrderIdList , out List<EmRepairOrderInfo> aOrderList, string sessionId);
                
        /// 主动从服务器获取数据, 更新一个报修单
        ///OrderPassInfo是流转状态表
        ///右键查看
        int GetOrderDetail(int aUserId, TOrderID aId, out List<EmRepairOrderStatusInfo> aOrderStatusInfo, string sessionId);

        /// (待定)
        /// 编辑一个报修单
        /// 改变工程单的状态不通过编辑保修单完成，用更安全的接口：PassOrder，编辑工程单只编辑其他内容
        int EditOrderCurStatusLevel(int aUserId , TOrderID aOrderID , int aLevel, string sessionId);
        
        //耗材
        int EditOrderSupplies(int aUserId, TOrderID aOrderID, string aConsumables, string sessionId);

        //下单部门编辑单
        int EditOrder(int aUserId, TOrderID aOrderId , string aName, string aDepartment, string aLocation, string aRepairObjectCode, string aRepairContentCode, int aLevel, string aNotes, string sessionId);

        /// <summary>
        /// 修改备注(对设备损坏的描述), 每个状态都可以有自己的备注
        /// </summary>
        /// <param name="aUserId"></param>
        /// <param name="aOrderID"></param>
        /// <param name="aNotes"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int EditOrderNotes(int aUserId, TOrderID aOrderID, string aNotes, string sessionId);
        
        /// <summary>
        /// 撤销一个报修单(未接单时)
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="sessionId"></param>
        /// <returns></returns>
        int CancelOrder( int aUserId , TOrderID aOrderId, string sessionId);
        

        ///流转工程表状态
        /// @Param aTime准确到秒
        /// aLevel == -1 不改变
        /// aConsumables == NULL 不改变
        /// 接单、验收（右键菜单为入口）等需要调用
        int PassOrder(int aUserId, TOrderID aOrderId, TOrderStatus aCurStatus, TOrderStatus aNextStatus, DateTime aTime, string aName, int aLevel, string aNotes, string aConsumables, string sessionId);
		
        ///获取保修区域类别总数
        int GetAreaNum( int aUserId , out int aNum , string sessionId);

        public class EmRepairAreaTreeNode
        {
            public int iFather;
            public string iAreaStr;//"区域#code"
        }

        //获得报修区域树
        int GetAllRepaireArea(int aUserId, out List<EmRepairAreaTreeNode> aAreaTree);
        
        ///获取保修区域
        ///@Param aAreaIndex为0表示区域1，为1表示区域2，如此类推
        ///@Param aAreaList区域列表
        /// @Param aAreaCodeList 代码列表
        /// @Param aAreaIndex -1表示所有区域(aAreaCodeList[0]为："区域1;区域2;区域3")，1表示区域1,2表示区域2等
        //int GetRepaireArea(int aUserId , int aAreaIndex , out List<string> aAreaList , out List<string> aAreaCodeList , string sessionId);
		
        ///搜索保修区域
        ///包括搜索区域代码和区域名，即aWord可是是代码或区域名的内容
        //int SearchRepaireAreaByFristWord(int aUserId , string aWord, int aAreaIndex , out List<string> aAreaList , out List<string> aAreaCodeList, string sessionId);

        ///简易搜索
        ///维修人员:输入配合选择（当前状态的）
        ///区域代码："区域1COde;区域2Code;"(建议搜索无)
        ///日期：指创建单的时间(一天的话是00:00-23:59)
        ///状态
        ///等级
        int SearchOrders(int aUserId, string aName, string aAreaCode, int aStatus, int aLevel, DateTime aBegDateTime, DateTime aEndDateTime, out List<TOrderID> aOrderIdList, string sessionId);
		
        //////////////////////////////能耗记录///////////////////////////////////////////////////
        ///获得分类树
        /// aTypeList是一个树形储存结构，双亲表示法
        int GetConsumeClassTree(int aUserId , out List<ConsumptionTree> aTypeList , string sessionId);

        ///获得某个树节点下的类别名
        /// @Param aNameList 是返回的类别名和id
        //int GetConsumeSubClassName(int aUserId , int aNodeId , out List<string> aNameList , out List<TConsumptionTreeID> aIdList,  string sessionId);

        ///获得某类别一个月的记录ID
        /// @Param aNodeId 是类别的ID
        /// @Param aRecdList 是这个类别的能耗记录列表
        int GetConsumptionRecordIdPerMonth(int aUserId , TConsumptionTreeID aNodeId ,int aYear , int aMonth ,  out List<TConsumptionRecdID> aRecdIdList , string sessionId);

        ///根据id获得记录内容
        /// @Param aRecdList 是这个类别的能耗记录列表
        int GetConsumptionRecord(int aUserId, List<TConsumptionRecdID> aIdList, out List<EmConsumptionRecd> aRecdList, string sessionId);

         ///获得当天的所有记录(总类的记录)
         /// @Param aDate 日期
         /// @Param aSubClassRecordList 当天所有记录
        //int GetConsumeDateRecord(int aUserId, TConsumptionTreeID aNodeId, DateTime aDate, out List<EmConsumptionRecd> aRecordList, string sessionId);
 
        ///新建一条总类的记录
         /// @Param aDate 日期
         /// @Param aSubClassRecordList 当天所有记录
        int NewConsumeRecord(int aUserId, List<EmConsumptionRecd> aSubClassRecordList, string sessionId);

        ///编辑一条总类的记录
        /// @Param aData 数据
        /// @Param aUnit 单价
        /// 弹窗编辑(单价默认为最迟的那条记录的单价)
        int EditConsumeDateRecord(int aUserId, int aRecdId , double aData, double aUnit, string sessionId);
    }
}
